1
Text Foundations: Chars vs Strings in Julia
AI015 Lesson 5
00:00

In Julia, text is handled via two distinct architectural entities: the 32-bit Char primitive and the immutable, UTF-8 encoded String. Unlike languages where a character is a one-length string, Julia treats Char as a first-class numeric type representing a Unicode code point.

1. Type Hierarchy & Memory

Concrete Char is a $32$-bit primitive type (subtype of AbstractChar). The built-in String (subtype of AbstractString) supports the full Unicode range. While a Char is fixed-size, String is variable-width; individual characters take 1 to 4 bytes, with the transition point for ASCII occurring at $0x80(128)$.

2. Arithmetic & Comparison

Since Char represents a numeric code point, you can perform arithmetic. Use Int('a') to get 97 and Char(97) to get 'a'. Lexicographical comparisons are supported: 'X' < 'x' is true because uppercase precedes lowercase in Unicode.

FeatureChar ('a')String ("a")
TypeCharString
SizeFixed $32$-bitVariable UTF-8
MutableN/A (Value Type)No (Immutable)

Chained comparisons like 'A' <= 'X' <= 'Y' evaluate to true or false based on the Unicode sequence.

main.py
TERMINAL bash — 80x24
> Ready. Click "Run" to execute.
>